package org.easy.core.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class R<T> {
    protected static final int SUCCESS = 0;
    protected static final int FAIL = 500;

    /**
     * 返回编码
     */
    private int code = 0;
    /**
     * 返回消息
     */
    private String msg;

    /**
     * 返回的对象
     */
    private T data;

    private R() {
    }



    public static <T> R<T> ok() {
        return new R<>();
    }

    public static <T> R<T> ok(T data) {
        return new R<>(SUCCESS, null, data);
    }

    public static <T> R<T> ok(int code, String msg) {
        return new R<>(code, msg, null);
    }

    public static <T> R<T> ok(int code, String msg, T data) {
        return new R<>(code, msg, data);
    }

    public static <T> R<T> fail() {
        return new R<>(FAIL, null, null);
    }

    public static <T> R<T> fail(String msg) {
        return new R<>(FAIL, msg, null);
    }

    public static <T> R<T> fail(int code, String msg) {
        return new R<>(code, msg, null);
    }

    public static <T> R<T> fail(int code, String msg, T message) {
        return new R<>(code, msg, message);
    }



}